package com.yy.train.ticket.train.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yy.train.ticket.into.page.BoxPage;
import com.yy.train.ticket.train.service.TtTrainSeatService;
import com.yy.train.ticket.utils.R;
import jdk.nashorn.internal.runtime.regexp.joni.Warnings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.yy.train.ticket.train.entity.TtTrainBoxEntity;
import com.yy.train.ticket.train.service.TtTrainBoxService;




/**
 * 车厢
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2023-09-26 09:47:24
 */
@RestController
@RequestMapping("tt/box")
public class TtTrainBoxController {
    @Autowired
    private TtTrainBoxService ttTrainBoxService;
    @Autowired
    private TtTrainSeatService ttTrainSeatService;
    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Long trainId){


        return R.ok(ttTrainBoxService.list(Wrappers.<TtTrainBoxEntity>lambdaQuery()
                .eq(StringUtils.checkValNotNull(trainId),TtTrainBoxEntity::getTrainId,trainId)));
    }
    /**
     * 列表
     */
    @PostMapping("/page")
    public R page(@RequestBody BoxPage trainPage){
      /*  LambdaQueryWrapper<TtTrainBoxEntity> lambdaQueryWrapper = Wrappers.lambdaQuery();
        Page<TtTrainBoxEntity> pages = new Page<TtTrainBoxEntity>(trainPage.getPageNum(), trainPage.getPageSize());
        IPage<TtTrainBoxEntity> iPage = ttTrainBoxService.page(pages, lambdaQueryWrapper);*/
        return  ttTrainBoxService.boxPage(trainPage);

    }
    @GetMapping("/trainId/{trainId}")
    public R train(@PathVariable("trainId") Long trainId){
        return ttTrainBoxService.getTrainBoxSeat(trainId);
    }

    /**
     * 信息
     */
    @GetMapping("/info/{boxId}")
    public R info(@PathVariable("boxId") Long boxId){
		TtTrainBoxEntity ttTrainBox = ttTrainBoxService.getById(boxId);

        return R.ok(ttTrainBox);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody TtTrainBoxEntity ttTrainBox){

        return ttTrainBoxService.saveBox(ttTrainBox);

    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody TtTrainBoxEntity ttTrainBox){

        return  ttTrainBoxService.updateTrainBoxById(ttTrainBox);

    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody List<Long> boxIds){
		ttTrainBoxService.removeByIds(boxIds);

        return R.ok();
    }

}
